//
//  LoginView.m
//  UI_豆瓣2.0
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LoginView.h"

@interface LoginView ()

@property (nonatomic, retain) UILabel *userNameLabel;
@property (nonatomic, retain) UILabel *passwordLabel;
@property (nonatomic, retain) UITextField *userNameTextField;
@property (nonatomic, retain) UITextField *passwordTextField;
@property (nonatomic, retain) UIButton *logonButton;

@end

@implementation LoginView

- (void)dealloc
{
    [_userNameLabel release];
    [_userNameTextField release];
    [_passwordLabel release];
    [_passwordTextField release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
    
    
    self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 150, 100, 30)];
    self.userNameLabel.backgroundColor = [UIColor clearColor];
    self.userNameLabel.text = @"用户名:";
    self.userNameLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:self.userNameLabel];
    [_userNameTextField release];
    
    
    self.passwordLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 230, 100, 30)];
    self.passwordLabel.backgroundColor = [UIColor clearColor];
    self.passwordLabel.text = @"密码:";
    self.passwordLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:self.passwordLabel];
    [_passwordLabel release];
    
    
    self.userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(130, 150, 200, 30)];
    self.userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.userNameTextField.placeholder = @"请输入用户名";
    self.userNameTextField.clearButtonMode = 4;
    self.userNameTextField.secureTextEntry = NO;
    [self addSubview:self.userNameTextField];
    [_userNameTextField release];
    
    
    self.passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(130, 230, 200, 30)];
    self.passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.passwordTextField.placeholder = @"请输入密码";
    self.passwordTextField.clearButtonMode = 4;
    self.passwordTextField.secureTextEntry = YES;
    [self addSubview:self.passwordTextField];
    [_passwordTextField release];
    
    
    self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginButton.backgroundColor = [UIColor colorWithRed:0.417 green:0.836 blue:0.428 alpha:1.000];
    self.loginButton.frame = CGRectMake(40, 300, 100, 50);
    [self.loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    [self addSubview:self.loginButton];
    [self.loginButton addTarget:self action:@selector(loginButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.logonButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.logonButton.backgroundColor = [UIColor colorWithRed:0.829 green:0.471 blue:0.179 alpha:1.000];
    self.logonButton.frame = CGRectMake(220, 300, 100, 50);
    [self.logonButton setTitle:@"注册" forState:UIControlStateNormal];
    [self addSubview:self.logonButton];
    [self.logonButton addTarget:self action:@selector(logonButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)loginButtonAction:(UIButton *)button{
    
    NSString *str1 = self.userNameTextField.text;
    NSString *str2 = self.passwordTextField.text;
    [self.loginDelegate presentToViewControllerName:str1 Password:str2];
    
}

- (void)logonButtonAction:(UIButton *)button{
    
    [self.loginDelegate presentToViewController];
    
}





/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
